package com.bodu.wxchat.service.impl;

import com.bodu.core.entity.enums.StatusFlagEnum;
import com.bodu.wxchat.entity.vo.WxchatMiniappConfigVo;
import com.bodu.core.entity.ParamReq;
import com.bodu.wxchat.entity.request.WxchatMiniappConfigRequest;
import com.bodu.wxchat.mapper.WxchatMiniappConfigMapper;
import com.bodu.wxchat.service.WxchatMiniappConfigService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 微信小程序配置 Service impl
 *
 * @author Administrator
 */
@Service
public class WxchatMiniappConfigServiceImpl implements WxchatMiniappConfigService {

    @Resource
    private WxchatMiniappConfigMapper wxchatMiniappConfigMapper;

    @Override
    public WxchatMiniappConfigVo getModel(Long id) {
        return wxchatMiniappConfigMapper.getModel(id);
    }

    @Transactional
    @Override
    public Long save(WxchatMiniappConfigRequest wxchatMiniappConfigRequest) {
        wxchatMiniappConfigMapper.save(wxchatMiniappConfigRequest);
        return wxchatMiniappConfigRequest.getId();
    }

    @Transactional
    @Override
    public Long update(WxchatMiniappConfigRequest wxchatMiniappConfigRequest) {
        wxchatMiniappConfigMapper.update(wxchatMiniappConfigRequest);
        return wxchatMiniappConfigRequest.getId();
    }

    @Override
    public List<WxchatMiniappConfigVo> listPage(ParamReq<WxchatMiniappConfigRequest> params) {
        params.setStartIndex((params.getCurrent() - 1) * params.getSize());
        List<WxchatMiniappConfigVo> list = wxchatMiniappConfigMapper.listPage(params);
        list.forEach(l -> l.setStatusFlagName(StatusFlagEnum.getStatusValues(l.getStatusFlag())));
        return list;
    }

    @Override
    public Integer countPage(ParamReq<WxchatMiniappConfigRequest> params) {
        return wxchatMiniappConfigMapper.countPage(params);
    }

    @Override
    public Integer updateDelFlagById(Long id, Integer delFlag) {
        return wxchatMiniappConfigMapper.updateDelFlagById(id, delFlag);
    }

    @Override
    public WxchatMiniappConfigVo getModelLimit1() {
        return wxchatMiniappConfigMapper.getModelLimit1();
    }
}
